package com.jinzecloud.fiction.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.jinzecloud.fiction.utils.PageUtils;
import com.jinzecloud.fiction.utils.R;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import com.jinzecloud.fiction.vo.TbAdminVo;
import com.jinzecloud.fiction.vo.TbAdminVos;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.jinzecloud.fiction.bean.TbAdmin;
import com.jinzecloud.fiction.service.TbAdminService;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;


/**
 * 后台管理员
 *
 * @author ??
 * @email 1971240051@qq.com
 * @date 2023-10-19 19:38:04
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("fiction/tbadmin")
//@Api(tags = "管理员 API 接口")
public class TbAdminController {
    @Autowired
    private TbAdminService tbAdminService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @ApiOperation(value = "查询用户列表", notes = "返回管理员分页列表",httpMethod = "GET")
    //@RequiresPermissions("fiction:tbadmin:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tbAdminService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/getUserInfo/{token}")
//    @ApiOperation(value = "管理员信息",notes = "根据id查询管理员",httpMethod = "GET")
    //@RequiresPermissions("fiction:tbadmin:info")
    public R getUserInfo(@PathVariable("token") String token){
        TbAdminVo tbAdminVo = tbAdminService.getUserInfo(token);

        return R.ok().put("tbAdmin", tbAdminVo);
    }
    @RequestMapping("/upStatus")
//    @ApiOperation(value = "修改管理员状态", notes = "只作为修改状态使用",httpMethod = "POST")
    //@RequiresPermissions("fiction:tbadmin:list")
    public R upStatus(@RequestBody TbAdmin tbAdmin){
        tbAdminService.updateStatus(tbAdmin);

        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{adId}")
//    @ApiOperation(value = "管理员信息",notes = "根据id查询管理员",httpMethod = "GET")
    //@RequiresPermissions("fiction:tbadmin:info")
    public R info(@PathVariable("adId") Integer adId){
		TbAdmin tbAdmin = tbAdminService.getById(adId);

        return R.ok().put("tbAdmin", tbAdmin);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @ApiOperation(value = "添加用户",notes = "添加管理员",httpMethod = "POST")
    //@RequiresPermissions("fiction:tbadmin:save")
    public R save(@RequestBody TbAdmin tbAdmin){
		tbAdminService.saveTbAdmin(tbAdmin);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @ApiOperation(value = "修改用户",notes = "修改管理员",httpMethod = "POST")
    //@RequiresPermissions("fiction:tbadmin:update")
    public R update(@RequestBody TbAdmin tbAdmin){
		tbAdminService.updateTbAdminById(tbAdmin);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @ApiOperation(value = "删除用户",notes = "删除管理员",httpMethod = "POST")
    //@RequiresPermissions("fiction:tbadmin:delete")
    public R delete(@RequestBody Integer[] adIds){
		tbAdminService.removeByIds(Arrays.asList(adIds));

        return R.ok();
    }

}
